package com.ruoyi.produce.base.shift.util;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * 用于生成编号的工具类
 * @author lsy 2021.8.16
 */
public class shiftInfoNoUtil {
    /**
     * 生成班次编号的工具类
     * @param day 某天 1-今天 2-明天 3-后天
     * @param num 班次 1-白班 2-夜班
     * @return
     */
    public static String createShiftInfoId(int day, int num) {
        Calendar nowtime = new GregorianCalendar();
        String shiftInfoId = "";
        if (day == 2) {
            // 生成明天班次
            nowtime.add(Calendar.DATE, 1); //获取到明天的日期
        }
        switch (num) {
            case 1 :
                String time1 = (String.format("%02d", nowtime.get(Calendar.YEAR)) +
                    String.format("%02d", nowtime.get(Calendar.MONTH) + 1) +
                    String.format("%02d", nowtime.get(Calendar.DATE))) + "01";
                shiftInfoId = time1;
                break;
            case 2:
                String time2 = (String.format("%02d", nowtime.get(Calendar.YEAR)) +
                        String.format("%02d", nowtime.get(Calendar.MONTH) + 1) +
                        String.format("%02d", nowtime.get(Calendar.DATE))) + "02";
                shiftInfoId = time2;
                break;
        }
        return shiftInfoId;
    }

    /**
     * 用于生成夜班的班次编号，班次号等于昨天02
     * @return
     */
    public static String getNightId() {
        Calendar nowtime = new GregorianCalendar();
        String shiftInfoId = "";
        nowtime.add(Calendar.DATE, -1); //获取到昨天的日期
        String time = (String.format("%02d", nowtime.get(Calendar.YEAR)) +
                String.format("%02d", nowtime.get(Calendar.MONTH) + 1) +
                String.format("%02d", nowtime.get(Calendar.DATE))) + "02";
        shiftInfoId = time;
//        System.out.println(shiftInfoId);
        return shiftInfoId;
    }
}
